package com.c.ctgproject.ui.review

import android.view.View
import com.c.ctgproject.R
import com.c.ctgproject.base.BaseActivity
import com.c.ctgproject.mode.MyConstants
import com.c.ctgproject.mode.UserMenuChildEnum
import com.c.ctgproject.ui.review.car.AbandonedCarActivity
import com.c.ctgproject.ui.review.material.MaterialReviewActivity
import com.c.ctgproject.ui.review.part.PartReviewActivity
import com.c.ctgproject.utils.*
import kotlinx.android.synthetic.main.activity_review_menu.*
import org.json.JSONArray
import org.json.JSONObject

/**
 *作者:LiBW
 *创建日期: 2020/9/9
 *描述: 审核菜单页面
 */
class ReviewHomeActivity : BaseActivity() {

    override fun getLayout() = R.layout.activity_review_menu
    override fun event() {
        changeTransparentStatusBar()
        changeStatusIconColor(true)
        val menu = intent.getStringExtra(MyConstants.MENUS)
        menu?.let {
            //隐藏所有 逐一展开
            mReviewMaterialLL.visibility = View.GONE
            mReviewPartLL.visibility = View.GONE
            mReviewCarLL.visibility = View.GONE
            mPlaceholder.visibility = View.INVISIBLE
            val jsonArray = JSONArray(it)
            repeat(jsonArray.length()) { j ->
                val json = JSONObject(jsonArray[j].toString())
                when (json.getString("menuCode")) {
                    UserMenuChildEnum.REVIEW_MATERIAL_SALE.menuCode -> mReviewMaterialLL.visibility = View.VISIBLE
                    UserMenuChildEnum.REVIEW_PARTS_SALE.menuCode -> mReviewPartLL.visibility = View.VISIBLE
                    UserMenuChildEnum.REVIEW_CAR_PRICE.menuCode -> mReviewCarLL.visibility = View.VISIBLE
                    UserMenuChildEnum.REVIEW_PARTS_SALE.menuCode -> mPlaceholder.visibility = View.VISIBLE
                }
            }
        }

//        //确认子菜单展示 暂时不上线
//        mReviewMaterialLL.visibility = if (UserMenuChildEnum.REVIEW_MATERIAL_SALE.menuCode in childList) View.VISIBLE else View.GONE
//        mReviewPartLL.visibility = if (UserMenuChildEnum.REVIEW_PARTS_SALE.menuCode in childList) View.VISIBLE else View.GONE
//        mReviewCarLL.visibility = if (UserMenuChildEnum.REVIEW_CAR_PRICE.menuCode in childList) View.VISIBLE else View.GONE
//        //占位item跟随配件销售展示
//        mPlaceholder.visibility = if (UserMenuChildEnum.REVIEW_PARTS_SALE.menuCode in childList) View.INVISIBLE else View.GONE
    }

    override fun click() {
        //设置
        mSettingIV.setOnClickListener {
            showPopupWindow(it)
        }
        //物料销售审核
        mReviewMaterialLL.setOnClickListener {
            startActivity<MaterialReviewActivity>()
        }
        //配件销售审核
        mReviewPartLL.setOnClickListener {
            startActivity<PartReviewActivity>()
        }
        //报废车价格审核
        mReviewCarLL.setOnClickListener {
            startActivity<AbandonedCarActivity>()
        }
    }

    override fun onBackPressed() {
        exitApp()
    }
}